<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.dao.db1.${classInfo.className}Dao">

  <resultMap id="BaseResultMap" type="${packageName}.bean.${classInfo.className}">
    <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
    <#list classInfo.fieldList as fieldItem >
        <result column="${fieldItem.columnName}" property="${fieldItem.fieldName}"/>
    </#list>
    </#if>
  </resultMap>

  <resultMap id="SpecResultMap" type="${packageName}.model.${classInfo.className}Model">
    <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
    <#list classInfo.fieldList as fieldItem >
        <result column="${fieldItem.columnName}" property="${fieldItem.fieldName}"/>
    </#list>
    </#if>
  </resultMap>

  <sql id="Base_Column_List">
    <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
    <#list classInfo.fieldList as fieldItem >
      ${fieldItem.columnName}<#if fieldItem_has_next>,</#if>
    </#list>
    </#if>
  </sql>

    <select id="selectCount" resultType="int"
            parameterType="${packageName}.model.${classInfo.className}Model">
        select count(1)
        from ${classInfo.tableName} a
        <where>
            <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
                <#list classInfo.fieldList as fieldItem >
                    <if test="${fieldItem.fieldName} != null and ${fieldItem.fieldName} !=''">
                        and a.${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}
                    </if>
                </#list>
            </#if>
        </where>
    </select>

    <select id="selectList" resultMap="SpecResultMap"
            parameterType="${packageName}.model.${classInfo.className}Model">
        select
        <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
            <#list classInfo.fieldList as fieldItem >
                a.${fieldItem.columnName}<#if fieldItem_has_next>,</#if>
            </#list>
        </#if>
        from ${classInfo.tableName} a
        <where>
            <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
                <#list classInfo.fieldList as fieldItem >
                    <if test="${fieldItem.fieldName} != null and ${fieldItem.fieldName} !=''">
                        and a.${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}
                    </if>
                </#list>
            </#if>
        </where>
        <if test="order != null and order !=''">
            order by   ${r"${"}order${r"}"}
        </if>
        <if test="isPage != null and isPage !=''">
            limit  ${r"#{"}pageStart${r"}"},${r"#{"}pageLength${r"}"}
        </if>
    </select>

  <insert id="insertSelective" parameterType="${packageName}.bean.${classInfo.className}">
    INSERT INTO ${classInfo.tableName}
    <trim prefix="(" suffix=")" suffixOverrides=",">
        		<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
        			<#list classInfo.fieldList as fieldItem >
        				<if test="${fieldItem.fieldName} != null and ${fieldItem.fieldName} != ''">
                  ${fieldItem.columnName},
                </if>
              </#list>
            </#if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
			<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
        			<#list classInfo.fieldList as fieldItem >
        				<if test="${fieldItem.fieldName} != null and ${fieldItem.fieldName} != ''">
                  ${r"#{"}${fieldItem.fieldName}${r"}"},
                </if>
              </#list>
      </#if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective"
          parameterType="${packageName}.bean.${classInfo.className}">
    UPDATE ${classInfo.tableName}
    <set>
        <#list classInfo.fieldList as fieldItem >
          <if test="${fieldItem.fieldName} != null and ${fieldItem.fieldName} != ''">
            ${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"},
          </if>
        </#list>
    </set>
    where
        <#if classInfo.keyList?exists && classInfo.keyList?size gt 0>
          <#list classInfo.keyList as fieldItem >
            ${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>
            and </#if>
          </#list>
        </#if>
  </update>

  <delete id="deleteByPrimaryKey" parameterType="${packageName}.bean.${classInfo.className}">
    DELETE FROM ${classInfo.tableName}
    where
    <#if classInfo.keyList?exists && classInfo.keyList?size gt 0>
      <#list classInfo.keyList as fieldItem >
        ${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>
        and </#if>
      </#list>
    </#if>
  </delete>

    <delete id="deleteBatch" parameterType="${packageName}.bean.${classInfo.className}">
        DELETE FROM ${classInfo.tableName} where
        <#if classInfo.keyList?exists && classInfo.keyList?size gt 0>
            <#list classInfo.keyList as fieldItem >
                ${fieldItem.columnName} in
            </#list>
        </#if>
        <foreach collection="list" open="(" close=")" separator="," item="item">
            <#if classInfo.keyList?exists && classInfo.keyList?size gt 0>
                <#list classInfo.keyList as fieldItem >
                    (${r"#{item."}${fieldItem.fieldName}${r"}"})
                </#list>
            </#if>
        </foreach>
    </delete>


    <select id="selectByPrimaryKey" parameterType="${packageName}.bean.${classInfo.className}"
          resultMap="SpecResultMap">
    select
		<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
            <#list classInfo.fieldList as fieldItem >
				a.${fieldItem.columnName}<#if fieldItem_has_next>,</#if>
            </#list>
        </#if>
    from ${classInfo.tableName} a
    where
			<#if classInfo.keyList?exists && classInfo.keyList?size gt 0>
        <#list classInfo.keyList as fieldItem >
          a.${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>
          and </#if>
        </#list>
      </#if>
  </select>


</mapper>
